package com.study.webapp.leetcode;

import java.util.Arrays;

/**
 * 最大子数组和
 * https://leetcode.cn/problems/maximum-subarray/
 */
public class Leet_53 {

	public static void main(String[] args) {
		int[] nums = new int[] {-2,1,-3,4,-1,2,1,-5,4};
		System.out.println(maxSubArray(nums));
	}


	public static int maxSubArray(int[] nums) {
		int a = 0; int c = nums[0];
		for (int i = 0; i< nums.length; i++) {
			a = Math.max(a+nums[i],nums[i]);
			c = Math.max(a,c);
		}
		return c;
	}

}
